import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home/Home'
import Login from '../views/Login/Login'
import Register from '../views/Register/Register'
import AudioPage from '../views/AudioPage/AudioPage'
Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/home/index'
    },
    {

        path: '/home',
        name: 'Home',
        component: Home,
        children: [
            {
                path: 'index',
                name: 'index',
                component: () => import('../views/Home/MainContent.vue')
            },
            {
                path: 'search/:_keywords',
                name: 'search',
                component: () => import('../views/SearchPage/SearchPage.vue')
            },
            {
                path: 'playlist-details/:_id',
                component: () => import('../views/PlayList/PlayList-Details.vue')
            },
            {
                path: 'rankinglist',
                name: 'rankinglist',
                component: () => import('../views/RankingList/RankingList.vue')
            },
            {
                path: 'songList',
                name: 'songList',
                component: () => import('../views/SongList/SongList.vue')
            },
            {
                path: 'singerList',
                name: 'singerList',
                component: () => import('../views/SingerList/SingerList.vue')
            },
            {
                path: 'mvList',
                name: 'mvList',
                component: () => import('../views/MvList/MvList.vue')
            },
            {
                path: 'mvDetails/:_id',
                name: 'mvDetails',
                component: () => import('../views/MvList/MvDetails')
            },
            {
                path: 'singerDetails',
                name: 'singerDetails',
                component: () => import('../views/SingerList/SingerDetails.vue'),
                children: [
                    {
                        path: 'art-musicList/:_id',
                        name: 'art-musicList',
                        component: () => import('../components/singerMusicList/SingerMusicList.vue')
                    },
                    {
                        path: 'art-album/:_id',
                        name: 'art-album',
                        component: () => import('../components/singerMusicList/SingerAlbumList.vue')
                    },
                    {
                        path: 'art-mv/:_id',
                        name: 'art-mv',
                        component: () => import('../components/singerMusicList/SingerMvsList.vue')
                    },
                    {
                        path: 'art-similar/:_id',
                        name: 'art-similar',
                        component: () => import('../components/singerMusicList/SingerSimilarList.vue')
                    },
                    {
                        path: 'art-text/:_id',
                        name: 'art-text',
                        component: () => import('../components/singerMusicList/SingerText.vue')
                    },

                ]
            }
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: Login
    },
    {
        path: '/register',
        name: 'register',
        component: Register
    },
    {
        path: '/musicAudio',
        name: 'musicAudio',
        component: AudioPage
    }

]

const router = new VueRouter({
    //路由（页面跳转时），滚动条显示在顶部  
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { x: 0, y: 0 }
        }
    },
    routes,
})
const isLogin = false;
// //全局前置守卫
// router.beforeEach((to, from, next) => {
//     console.log('守卫触发');
//     console.log(to);
//     // next();
//     if (to.fullPath == '/home/index') {
//         if (isLogin) {
//             next();
//         } else {
//             alert('你还未登录，请先登录')
//             if (from.name != 'login') {
//                 next('/login')
//             }
//         }
//     }
//     else {
//         next();
//     }
// })

export default router
